package com.sc.javaee.service.impl;

import com.sc.javaee.mapper.AddressMapper;
import com.sc.javaee.pojo.Address;
import com.sc.javaee.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {
   @Autowired
    AddressMapper mapper;
   @Transactional
    public Address add(Address a) {
        int row=mapper.insert(a);
        return row>0 ? a : null;
    }
    @Transactional
    public int del(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Transactional
    public int update(Address a) {
        return mapper.updateByPrimaryKeySelective(a);
    }

    public List<Address> select() {
        return mapper.selectAddress();
    }

    public Address selectByAddressId(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Transactional
    public int updateStatus() {
        return mapper.updateStatus();
    }

    public Address getDefaultAddress() {
        return mapper.getDefaultAddress();
    }
}
